package ThroughputDelay.IO;

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.Socket;

public class ClientThrDelIO {
    public static void main(String[] args) {

        for (int j = 0; j < ServerThrDelIO.POOL_SIZE; j++) {
            new Thread(() -> {
                try (Socket socket = new Socket("localhost", 7003);
                     ObjectInputStream is = new ObjectInputStream(socket.getInputStream());
                     DataOutputStream os = new DataOutputStream(socket.getOutputStream())) {

                    switch (ServerThrDelIO.mode){
                        case THROUGHPUT:
                            for (int i = 0; i < ServerThrDelIO.MESSAGE_COUNT; i++) {
                                is.readObject();
                            }
                            break;
                        case DELAY:
                            for (int i = 0; i < ServerThrDelIO.MESSAGE_COUNT; i++) {
                                os.writeUTF("GET");
                                is.readObject();
                                os.writeUTF("CONFIRM");
                            }
                            os.writeUTF("STOP");
                            break;
                    }
                } catch (IOException | ClassNotFoundException e) {
                    e.printStackTrace();
                }
            }).start();
        }
    }
}
